<template>
  <div class="valueset">
    <div class="outmain ba_f">
      <div class="shuju_title mar_b20">
        <div class="shuju_title_text">
          <span>存酒设置</span>
        </div>
      </div>
      <el-form ref="form" :model="form" label-width="180px">
        <el-form-item label="存酒审核">
          <el-radio-group v-model="form.isCheck">
            <el-radio label="1">开启</el-radio>
            <el-radio label="2">关闭</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="存酒有效期">
          <el-input-number v-model="form.days" :min="10" :max="10000000"></el-input-number>
          <span class="mar_l10">天</span>
          <div class="yb_margin lh16">存酒有效期,单位天!默认10天</div>
        </el-form-item>
        <el-form-item label="存酒提示语">
          <el-input v-model="form.slogan" placeholder="请输入存酒提示语"></el-input>
        </el-form-item>
        <el-form-item label="广告位">
          <div class="uploadSource bor_de rel flex curs" v-if="form.icon">
            <label class="statusLabel curs"  @mouseenter="enter(1)" @mouseleave="leave(1)">
              <i class="el-icon-check" ref="imgicon1"></i>
              <i class="el-icon-close" @click="deleteMultiImage(form.icon,1)"></i>
            </label>
            <img :src="form.icon" @click='test(1)' class="wid"/>
          </div>
          <div class="uploadSource flex-center curs" v-else @click='test(1)'>
            <i class="el-icon-plus fon_40 color_d9"></i>
          </div>
          <div class="yb_margin lh16">*建议宽高750*320px</div>
          <attachment-img ref="img1" type="img" @attachment='imgadd1'></attachment-img>
        </el-form-item>
        <el-form-item label="存酒协议">
          <baidu-ueditor :content="form.details" @ueditor="getUeditor"></baidu-ueditor>
        </el-form-item>
      </el-form>
    </div>
    <div class="mar_t20 ba_f pad_20 t_c">
      <el-button type="primary" @click="submitForm">保存</el-button>
    </div>
  </div>
</template>
<script>
import { getStoreConfig, postStoreConfig } from '@/api/setup';
import baiduUeditor from '@/plugins/baidu-ueditor';
import attachmentImg from "@/plugins/attachment-img";
export default {
  components: { baiduUeditor,attachmentImg},
  created() {
    this.bus.$emit('loading', true);
    this.init();
  },
  data() {
    return {
      form: {
        isCheck: '1',
        days: '10',
        slogan: '',
        content: '',
        details: '',
        icon: '',
      }
    };
  },
  methods: {
    getUeditor(content) {
      this.form.details = content;
    },
    enter(i=0){
      this.$refs['imgicon' + i].style.display = 'none'
    },
    leave(i=0){
      this.$refs['imgicon' + i].style.display = 'inline-block'
    },
    test(i = 0) {
      this.$refs['img' + i].dialogVisible = true
    },
    imgadd1(url) {
      this.form.icon = url.str
    },
    deleteMultiImage(item, index, type) {
      //typem没传是单图multigraph多图；index上传图片组件排序
      Array.prototype.remove = function (val) {
        var index = this.indexOf(val);
        if (index > -1) {
          this.splice(index, 1);
        }
      };
      if (type == 'multigraph') {
        switch (index) {
          case 2:
            this.form.icon.remove(item);
            break
        }
      } else {

        switch (index) {

          case 1:
            this.form.icon = '';
            break
        }
      }

    },
    async init() {
      const { data } = await getStoreConfig({ ident: 'storageSet' });
      this.form2 = this.form;
      this.form = Object.assign(this.form2, data);
      this.bus.$emit('loading', false);
    },
    submitForm() {
      this.$refs['form'].validate(async (valid) => {
        if (valid) {
          this.form.ident = 'storageSet';
          this.form.identName = '存酒配置';
          this.form.storeId = '';
          const { msg } = await postStoreConfig(this.form);
          this.$baseMessage(msg, 'success');
          this.init();
        } else {
          return false;
        }
      });
    }
  }
};
</script>
